package com.iot.spi.response;

import cn.hutool.core.util.RandomUtil;

import java.io.Serializable;

/**
 * 响应信息主体
 *
 * @author iot
 */
public class Resp<T> implements Serializable
{
    private static final long serialVersionUID = 1L;

    private String traceId;

    private int code;

    private String msg;

    private T data;

    public Resp() {
    }
    public Resp(String traceId, int code, String msg, T data) {
        this.traceId = traceId;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public Resp(int code, String msg) {
        this.traceId = RandomUtil.randomString(32);
        this.code = code;
        this.msg = msg;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> Resp<T> fail(String msg)
    {
        return new Resp(1005, msg);
    }

}
